home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_demo-version / egs_devels / examples / egs_menu / main.c < prev    next >
C/C++ Source or Header  |  1994-06-06  |  3KB  |  163 lines

  1. /*
  2. **  Author: Markus van Kempen
  3. **  Date  : 17. Dezember 1992
  4. **
  5. **  This demo shows the easy way to create
  6. **  EGS menus. See InitMenu.c for the menu definition.
  7. **  The other routines are for OpenLibs, event
  8. **  and error handling.
  9. **
  10. **  In these files you will find some useful routines
  11. **  for Open / Close libraries and error handling.
  12. **
  13. **  (c) by VIONA-Development
  14. **
  15. */
  16.  
  17. #include "includes.c"
  18. #include "Global.h"
  19. #include "Eventloop.c"
  20. #include "InitMenu.c"
  21.  
  22. BOOL            InitLibraries(struct OpenStructTyp *);
  23. void            CloseLibraries(struct OpenStructTyp *);
  24.  
  25. /*
  26. **  Opens the libs defined by a structure with OpenStruct type
  27. **  (see global.h)
  28. **
  29. */
  30.  
  31. BOOL
  32. InitLibraries(struct OpenStructTyp *OS)
  33. {
  34.     struct OpenStructTyp *p = &OS[0];
  35.  
  36.     while (p->Ort != NULL)
  37.     {
  38.         if ((*(p->Ort) = (ULONG) OpenLibrary(p->Name, p->Version)) == NULL)
  39.         {
  40.             printf(" Can't open %s version %d", p->Name, p->Version);
  41.             return FALSE;
  42.         }
  43.         else
  44.         {
  45.             p++;
  46.         }
  47.     }
  48.     return TRUE;
  49. }
  50.  
  51.  
  52. /*
  53. ** Close the libs
  54. **
  55. */
  56.  
  57. void
  58. CloseLibraries(struct OpenStructTyp *OS)
  59. {
  60.     struct OpenStructTyp *p = &OS[0];
  61.  
  62.     while (*(p->Ort) != NULL && p->Name != NULL)
  63.     {
  64.         CloseLibrary((void *) (*(p->Ort)));
  65.         *(p->Ort) = NULL;
  66.         p++;
  67.     }
  68. }
  69.  
  70. /*
  71. ** This routine is for error handling.
  72. ** It closes all open things of the
  73. ** program.
  74. **
  75. */
  76. void
  77. myError(char   *string)
  78. {
  79.     if (string != NULL)
  80.     {
  81.         if (EGSRequestBase == NULL)
  82.         {
  83.             printf("%s\n", string);
  84.         }
  85.         else
  86.         {
  87.             ErrorReq = (ER_SimpleRequestPtr) ER_CreateSimpleRequest(NULL,
  88.                                             (char *) string, (char *) "OK");
  89.             /*
  90.         **  Open requester in the middle of the screen,
  91.             **
  92.         **  if you can!
  93.             */
  94.  
  95.             ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
  96.  
  97.             ER_DoRequest(&(ErrorReq->Req));
  98.         }
  99.     }
  100.     if (Window)
  101.     {
  102.         ErrorReq = ER_CreateSimpleRequest(NULL,
  103.                                "Hello world !|This is a Requester !", "OK");
  104.  
  105.         ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
  106.         ER_DoRequest(&(ErrorReq->Req));
  107.     }
  108.     if (FontforMenu)
  109.         EG_CloseFont(FontforMenu);
  110.  
  111.     if (Window)
  112.         EI_CloseWindow(Window);
  113.  
  114.     if (Menu)
  115.         EI_FreeMenu(Menu);
  116.  
  117.     if (ErrorReq)
  118.         ER_DeleteRequest(&(ErrorReq->Req));
  119.  
  120.     CloseLibraries(OpenStruct);
  121.     exit(0);
  122. }
  123.  
  124.  
  125. int
  126. main(int argc, char *argv[])
  127. {
  128.     if (argc == 2 && strcmp("?", argv[1]) == 0)
  129.     {
  130.         printf("Aufruf: %s\n  Markus van Kempen 12 Nov 1992", argv[0]);
  131.     }
  132.     else
  133.     {
  134.         if (InitLibraries(OpenStruct) == FALSE)
  135.             myError("Can't OpenLibrary");
  136.  
  137.         FontforMenu = (EG_EFontPtr) EG_OpenFont((struct TextAttr *) & FontStr);
  138.  
  139.         if (FontforMenu == NULL)
  140.             myError("Could not open font");
  141.  
  142.         Menu = InitMenu(FontforMenu);
  143.  
  144.         if (Menu == NULL)
  145.             myError("Could not build menu");
  146.  
  147.         newwin.Menu = Menu;
  148.         newwin.Title = argv[0];
  149.  
  150.         Window = (EI_WindowPtr) EI_OpenWindow((struct EI_NewWindow *) & newwin);
  151.  
  152.         if (Window)
  153.         {
  154.             HandleEvents(Window);
  155.         }
  156.         else
  157.         {
  158.             myError("Could not open window");
  159.         }
  160.     }
  161.     myError(NULL);
  162. }
  163.